package com.example.flow.dao.impl;

import com.example.flow.dao.FlowOrderDao;
import com.example.flow.dao.mapper.FlowOrderMapper;
import com.example.flow.dao.model.FlowOrder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author tangaq
 * 2023/6/15
 */
@Service
public class RdsFlowOrderDaoImpl implements FlowOrderDao {
    private final FlowOrderMapper flowOrderMapper;

    public RdsFlowOrderDaoImpl(FlowOrderMapper flowOrderMapper) {
        this.flowOrderMapper = flowOrderMapper;
    }


    @Override
    public FlowOrder findByOrderId(String orderId) {
        if (StringUtils.isBlank(orderId)) {
            return null;
        }
        FlowOrder query = new FlowOrder();
        query.setOrderId(orderId);
        return flowOrderMapper.selectOne(query);
    }

    @Override
    public boolean checkProcessIsUsing(String processId) {
        if (StringUtils.isBlank(processId)) {
            return false;
        }
        FlowOrder query = new FlowOrder();
        query.setProcessId(processId);
        return flowOrderMapper.delete(query) != 0;
    }

    @Override
    public void deleteByOrderId(String orderId) {
        if (StringUtils.isBlank(orderId)) {
            return;
        }
        FlowOrder query = new FlowOrder();
        query.setOrderId(orderId);
        flowOrderMapper.delete(query);
    }

    @Override
    public void insert(FlowOrder order) {
        flowOrderMapper.insert(order);
    }
}
